/*DateSearchBar.js*/

import React, {Component} from 'react';
import {connect} from 'dva';
import {routerRedux} from 'dva/router';
import {
	Card, Row, Col,message,
	Form,DatePicker,Button,
 } from 'antd';
import moment from 'moment';

const { RangePicker } = DatePicker;
const dateFormat = 'YYYYMMDD';

const DateRangePicker=({dispatch,begindate,enddate,tag})=>{
	console.log('DateRangePicker>>>',begindate,enddate,tag)
	const myProps={
		onChange:(v)=> {
			if(v.length){
				dispatch({
					type: `${tag}/setState`,
					payload: {
						begindate:v[0].format("YYYYMMDD"),
						enddate:v[1].format("YYYYMMDD")
					}
				})
			}else{
				dispatch({
					type: `${tag}/setState`,
					payload: {
						begindate:'',
						enddate:''
					}
				})
			}

		},
		style:{width:130}
	}
	if(begindate){
		myProps.defaultValue=[moment(begindate), moment(enddate)]
	}

	return (
		<RangePicker
			{...myProps}
			// format="YYYY/MM/DD"
			//style={{ width: 200 }}
			style={{ width: 212 }}
			/>
	)
}

export default connect(({})=>({}))(DateRangePicker)